package com.easytouch.vmhdl.view;

import android.graphics.Bitmap;
import android.util.Log;

import com.easytouch.vmhdl.interfaces.ClickSwitchListener;


public class BitmapTouchChecker implements MainButton.TouchChecker {
	private ClickSwitchListener mListener = null;
	private Bitmap bitmap;

	public boolean a, b, c = false;

	public BitmapTouchChecker(Bitmap bitmap) {
		this.bitmap = bitmap;
	}

	@Override
	public boolean isInTouchArea(int x, int y, int width, int height) {
		if (bitmap != null) {
			if(x >= bitmap.getWidth() || y >= bitmap.getHeight())
			{
				return false;
			}
			int pixel = bitmap.getPixel(x, y);
			boolean isTransparent = false;
			if (pixel == 0)
				isTransparent = true;
			pixel = pixel & 0x00FFFFFF;

			if (pixel == 0 && !isTransparent) {
				// 黑色
				a = true;
				mListener.onClickSwitchListener(1);
				return true;
			} else if (((pixel & 0x0000FF00) >> 8) > 0) {
				// 绿色
				b = true;
				mListener.onClickSwitchListener(2);
				return true;
			} else if ((pixel & 0x000000FF) > 0) {
				// 蓝色
				c = true;
				mListener.onClickSwitchListener(3);
				return true;
			}
		}

		Log.d("BitmapTouchChecker", "isInTouchArea return false");

		return false;
	}

	public void setListener(ClickSwitchListener listener) {
		this.mListener = listener;
	}
}
